class InterfaceGen
{

	// interface generator, mainly intended for flash game guis.
	// this doesn't define an entire gui, but rather the underlying structure: hierarchy and
	// basic data like x/y positioning and inherited classes. 

	public static function main()
	{
		// load a hierarchyfile and a descfile
		// combine the two into class instances
		
		// in a separate file create a loop to update the resulting ui
		
		var hierarchynodes = HierarchyParser.read(neko.io.File.getContent("creep.hierarchy"));
		var confighash = ConfigParser.read(neko.io.File.getContent("creep.config"));
		
		var result = new StringBuf();

		result.add("class Interface\n"+
				   "{\n");

		var decl = new StringBuf();
		var new_vars = new StringBuf();
		var inits = new StringBuf();

		for (widget in confighash.keys())
		{
			var mydecl : String = null;
			for (entry in confighash.get(widget).keys())
			{
				var data = confighash.get(widget).get(entry);
				switch(entry) // custom behavior for "odd" settings goes here
				{
					default:
						new_vars.add(
							"        "+widget+"."+entry+" = "+data+";\n");
					case("class"):
						mydecl = "    public var "+widget+" : "+data+";\n";
						inits.add("        "+widget+" = new "+data+"();\n");
				}
			}			
			if (mydecl==null) throw "widget named "+widget+" needs a class";
			decl.add(mydecl);
		}

		
		result.add(decl.toString());
		
		result.add("    public function new()\n"+
				   "    {\n");
		result.add(inits.toString());
		result.add(new_vars.toString());
		
		for (n in hierarchynodes)
		{
			if (n.children.length>0)
			{
				for (c in n.children) // no need for fancy recursion, we have the full list
					result.add("        "+n.name+".addChild("+c.name+");\n");					
			}
		}

		result.add("    }\n");
		result.add("}\n");

		trace(result.toString());
	}

}

